package com.qf.first.service.Impl;

import com.qf.first.base.pojo.vo.UserVo;
import com.qf.first.entity.User;
import com.qf.first.mapper.UserMapper;
import com.qf.first.pojo.request.UserRequest;
import com.qf.first.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public UserVo checkUsername(String username) {
        User user = userMapper.selectUserByName(username);
        UserVo userVo = new UserVo();
        if (user!=null){
            BeanUtils.copyProperties(user,userVo);
            return userVo;
        }

        return null;
    }

    @Override
    public int addUser(UserRequest userRequest) {
        User user = new User();
        BeanUtils.copyProperties(userRequest,user);
        int insert = userMapper.insert(user);
        return insert;
    }
}
